package edu.mit.simile;

import java.util.ArrayList;
import java.util.List;

import com.hp.hpl.jena.query.DataSource;
import com.hp.hpl.jena.query.Dataset;
import com.hp.hpl.jena.query.DatasetFactory;
import com.hp.hpl.jena.query.Query;
import com.hp.hpl.jena.query.QueryExecution;
import com.hp.hpl.jena.query.QueryExecutionFactory;
import com.hp.hpl.jena.query.QueryFactory;
import com.hp.hpl.jena.query.QuerySolution;
import com.hp.hpl.jena.query.ResultSet;

public class TestJoseki {

	static String graph = "http://okkam.it/mygraph";
	static String queryString = "SELECT ?s ?p ?o WHERE { ?s ?p ?o . } LIMIT 10";
	static String service = "http://127.0.0.1:2020/taxproject?query=SELECT";
	public static void main (String [] args) {
		
		Query query = QueryFactory.create(queryString) ;
		
		DataSource dataSource = DatasetFactory.create() ;
		
		List namedGraphURIs = new ArrayList();
		
		namedGraphURIs.add(graph);
		
		List defaultGraphURIs = null;

		Dataset dataset = DatasetFactory.create(service);
		System.out.println("create dataset and query");
		//QueryExecution qexec = QueryExecutionFactory.sparqlService(service, query, defaultGraphURIs, namedGraphURIs) ;
		
		QueryExecution qexec = QueryExecutionFactory.create(query, dataset) ;
		
		try {
			ResultSet results = qexec.execSelect() ;
	          for ( ; results.hasNext() ; )
	          {
	              QuerySolution solution = results.nextSolution() ;              
	              System.out.println("object = " + solution.toString()) ;
	          }
	     } finally { qexec.close() ; }
	     qexec.close();
	}
}